<!--
  - Copyright (c) 2023.
  -
  - 作者：bmy
  - 邮箱：2271608011@qq.com
  - gitee：https://gitee.com/bmycode
  - github：https://github.com/helpcode
  -
  -->

<script lang="ts">
  import { onMount } from "svelte";
  import Layout from '@/component/layout.svelte';
  import { NativeSelect, RadioGroup } from '@svelteuidev/core';
  import config from '@/config';
  import { themeConfig } from '@/stores/ThemeStore';
  import JsonDatabase from "@/utils/JsonDatabase";

  let JsonTypeSelect = String($themeConfig.JsonType)
  let needPropertySelect = String($themeConfig.needProperty)
  let needPropertyValueSelect = String($themeConfig.needPropertyValue)

  let NullAliasSelect = $themeConfig.nullAlias
  let NullAliasList = ['string', 'number', 'object', 'any']

  onMount(() => {

  });

</script>

<div class="basis">
    <Layout text="基础设置">
        <RadioGroup
                label="JSON转化为: "
                description="将json转化为 class 类 还是 interface 接口"
                direction="column"
                labelDirection="left"
                items={config.offOrOnList(1)}
                bind:value={JsonTypeSelect}
                on:change={() => {
                   $themeConfig.JsonType = Number(JsonTypeSelect)
                    JsonDatabase.writeJson($themeConfig)
                }}/>

        <RadioGroup
                label="Property 装饰器: "
                description="选择 class 后，是否为类自动生成 json-mapper-class 插件的 Property 装饰器"
                direction="column"
                labelDirection="left"
                items={config.offOrOnList()}
                bind:value={needPropertySelect}
                on:change={() => {
                   $themeConfig.needProperty = Number(needPropertySelect)
                    JsonDatabase.writeJson($themeConfig)
                }}/>

        <RadioGroup
                label="Property 装饰器默认值: "
                description="为 Property 装饰器自动生成默认值"
                direction="column"
                labelDirection="left"
                items={config.offOrOnList()}
                bind:value={needPropertyValueSelect}
                on:change={() => {
                   $themeConfig.needPropertyValue = Number(needPropertyValueSelect)
                   JsonDatabase.writeJson($themeConfig)
                }}/>

        <NativeSelect data={NullAliasList}
              placeholder=""
              bind:value={NullAliasSelect}
              label="null 默认类型: "
              on:input={() => {
                $themeConfig.nullAlias = NullAliasSelect
               JsonDatabase.writeJson($themeConfig)
              }}
              description="如果JOSN中某对象的值为 null，转化为 class 或 interface 时候，给这个对象key个默认类型"
        />

    </Layout>
</div>

<style lang="less">
  @import "../assets/less/_.less";

  .basis {

  }
</style>